package 预习;

public class 偶数索引累加和 {
    public static void main(String[] args) {
        int[] arr = {21, 28, 12, 24, 12, 26};

        int sum = printArrays(arr);

        System.out.println("这个数组偶数的和是"+sum);
    }

    public static int printArrays(int[] arr) {

        //int[] arr01 = new int[(arr.length + 1) / 2];
        int sum = 0;
        //遍历这个数组
        for (int i = 0; i < arr.length; i++) {
            //判断条件
            if (i % 2 == 0 && arr[i] % 2 == 0) {
                sum += arr[i];

            }
        }
        return sum;
    }
}
